﻿using System.Globalization;
using System.Net.Http;
using CkSoftware.GroupMe.Sdk.Core;
using CkSoftware.GroupMe.Sdk.Core.Dao;
using CkSoftware.GroupMe.Sdk.Groups.Dao;

namespace CkSoftware.GroupMe.Sdk.Groups.Commands
{
	internal class UpdateGroupCommand : IWebApiCommand<GroupMeApiResponse<GroupData>>
	{
		private readonly string _groupId;
		private readonly CreateGroupParameters _parameters;

		public UpdateGroupCommand(string groupId)
		{
			_groupId = groupId;
			_parameters = new CreateGroupParameters();
		}

		public bool CommandExecuted { get; set; }

		public string CommandName
		{
			get { return string.Format(CultureInfo.CurrentCulture, "groups/{0}/update", _groupId); }
		}

		public HttpMethod HttpMethod
		{
			get { return HttpMethod.Post; }
		}

		public IWebApiCommandParameters Parameters
		{
			get { return _parameters; }
		}

		public UpdateGroupCommand OpenForSharing()
		{
			_parameters.IsOpenForSharing = true;
			return this;
		}

		public UpdateGroupCommand WithDescription(string description)
		{
			_parameters.Description = description;
			return this;
		}

		public UpdateGroupCommand WithImage(string imageUrl)
		{
			_parameters.ImageUrl = imageUrl;
			return this;
		}

		public UpdateGroupCommand WithImage(PictureData imageData)
		{
			_parameters.GroupImage = imageData;
			return this;
		}

		public UpdateGroupCommand WithName(string groupName)
		{
			_parameters.Name = groupName;
			return this;
		}
	}
}